package models;


import models.crudsiena.SienaSupport;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;
import play.i18n.Lang;
import play.modules.siena.EnhancedModel;
import siena.*;
import siena.core.Aggregated;
import siena.core.Many;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TinTuc extends SienaSupport{
    @Id(Generator.AUTO_INCREMENT)
    public Long id;

    @DateTime
    public Date timeModified;

    @NotNull
    public String title;

    @NotNull
    public String brief;

    @Max(32000)
    public String content;
    
    //public byte[] photo;

    public String language;

    public TinTuc() {
    }

    public TinTuc(Date timeModified, String title, String brief, String content) {
        this.timeModified = timeModified;
        this.title = title;
        this.brief = brief;
        this.content = content;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getTimeModified() {
        return timeModified;
    }

    public void setTimeModified(Date timeModified) {
        this.timeModified = timeModified;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getBrief() {
        return brief;
    }

    public void setBrief(String brief) {
        this.brief = brief;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    //YYYY-MM-DD hh:mm:ss
    public void setTimeModified(String time) {
        DateFormat df = new SimpleDateFormat(Constants.DATE_TIME_FORMAT);
        try {
            this.timeModified = df.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
            this.timeModified = Calendar.getInstance().getTime();
        }
    }
}
